﻿using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.SignalR.Client;
namespace TrackSystem.UI.Server.Units.UserAlarm;

/// <summary>
/// 报警控制视图
/// </summary>
public partial class AlarmControl
{
    [Parameter]
    public Dictionary<Guid, string>? AlarmMsg { get; set; }

    [Parameter]
    public int AlarmNums { get; set; }

    [Parameter]
    public HubConnection hub { get; set; }

    /// <summary>
    /// 确认报警
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    private async Task BtnComfimAlarm(Guid id)
    {
        try
        {
            if (hub.State == HubConnectionState.Connected)
            {
                await hub.SendAsync("ConfirmAlarm", id);
            }
        }
        catch (Exception _)
        {
            // Ignored
        }
    }

    /// <summary>
    /// 隐藏报警
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    private async Task BtnHiddenAlarm(Guid id)
    {
        try
        {
            if (hub.State == HubConnectionState.Connected)
            {
                await hub.SendAsync("HiddenAlarm", id);
            }
        }
        catch (Exception _)
        {
            // ignored
        }
    }

    /// <summary>
    /// 显示所有报警
    /// </summary>
    /// <returns></returns>
    private async Task BtnShowAllAlarm()
    {
        try
        {
            if (hub.State == HubConnectionState.Connected)
            {
                await hub.SendAsync("BtnShowAllAlarm");
            }
        }
        catch (Exception _)
        {
            // ignored
        }
    }

}
